## DESCRIPTION
## Precalculus: dynamically generated graph of a function
## ENDDESCRIPTION

## KEYWORDS('precalculus', 'dynamic graph')

## DBsubject('WeBWorK')
## DBchapter('WeBWorK Tutorial')
## DBsection('Fort Lewis Tutorial 2011')
## Date('01/30/2011')
## Author('Paul Pearson')
## Institution('Fort Lewis College')
## TitleText1('')
## EditionText1('')
## AuthorText1('')
## Section1('')
## Problem1('')


#############################################
#  Initialization

DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"AnswerFormatHelp.pl",
"PGgraphmacros.pl",
"unionTables.pl",
);

TEXT(beginproblem());

$refreshCachedImages = 1;


##############################################
#  Setup

Context("Numeric");

$a = random(2,3,1); # left x-intercept
$b = random(2,4,2); # right x-intercept
$c = random(5,6,1); # y-intercept

$k = -($c)/($a * $b);

$A = $k;
$B = $k*($a - $b);
$C = -($k * $a * $b);

#
#  Graph canvas
#
$gr = init_graph(-5,-1,5,9,axes=>[0,0],grid=>[10,10],size=>[300,300]);
$gr -> lb('reset');

#
#  Graph labels and functions
#
$gr -> lb(new Label ( 4.5,0,'x','black','left','bottom'));
$gr -> lb(new Label ( 0.25,8.5,'y','black','left','bottom'));
$gr -> lb(new Label ( 0.25,$c,'y = f(x)','black','left','bottom'));
foreach my $i (1..4) {
  $gr -> lb(new Label ( $i,-0.5, $i,'black','center','middle'));
  $gr -> lb(new Label (-$i,-0.5,-$i,'black','center','middle'));
}
foreach my $j (1..8) {
  $gr -> lb(new Label (-4.5,$j,$j,'black','center','middle'));
}
add_functions($gr, "$A*x**2+$B*x+$C for x in <-5,5> using color:blue and weight:2");



#############################################
#  Main text

Context()->texStrings;
BEGIN_TEXT
\{
ColumnTable(
"Use the graph to find the missing values.  
There may be more than one correct answer, 
in which case you should enter your answers
as a comma separated list.  If there are no
correct answers, enter ${BITALIC}NONE.${EITALIC}
$BR
$BR
(a) \( f(0) = \) " . 
ans_rule(7).$SPACE.
AnswerFormatHelp("numbers").
"$BR
$BR
(b) \( f \big( \) ".ans_rule(7)." \( \big) = 0 \). ".
AnswerFormatHelp("numbers")
,
image(insertGraph($gr), width=>300, height=>300, tex_size=>700).
$BR.$BCENTER.
$BR.
"Graph of \( y = f(x) \)".
$ECENTER
,
indent => 0, separation => 30, valign => "TOP"
)
\}
END_TEXT
Context()->normalStrings;


###############################################
#  Answer evaluation

$showPartialCorrectAnswers = 1;

ANS(List($c)->cmp() );

ANS(List(-$a,$b)->cmp() );


############################
#  Solution

Context()->texStrings;
BEGIN_SOLUTION
${PAR}SOLUTION:${PAR}
Solution explanation goes here.
END_SOLUTION
Context()->normalStrings;

COMMENT('MathObject version.');

ENDDOCUMENT();
